﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data;

public partial class Ajax_shuangsesw : System.Web.UI.Page
{
    public List<Model.LotteryAnnouncement> GetPageListSQl(int PageIndex, int PageSize, string sql, out int totalCount)
    {
        string primaryKey = "openTime";
        totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, sql);
        return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " desc", sql);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext c = HttpContext.Current;
        string shouqiujiou = "";
        string shouqiudx = "";
        string shouqiusanlu = "";
        string weiqiujiou = "";
        string weiqiudx = "";
        string weiqiusanlu = "";
        string shouweihezhijiou = "";
        string shouweihezhidx = "";
        string shouweihezhisanlu = "";
        int lotteryType = ReadRequest.RequestInt("type");
        int count = ReadRequest.RequestInt("counts");
        int qsType = ReadRequest.RequestInt("qsType");
        int totalCount = 0;
        string sql = "";
        if (qsType == 1)
        {
            sql = " LotteryType =" + lotteryType + " and LotteryQS% 2= 1";
        }
        else if (qsType == 2)
        {
            sql = " LotteryType =" + lotteryType + " and LotteryQS% 2= 0";
        }
        else if (qsType == 3)
        {
            sql = " LotteryType =" + lotteryType + " and datepart(weekday,openTime)=3";//周二
        }
        else if (qsType == 4)
        {
            sql = " LotteryType =" + lotteryType + " and datepart(weekday,openTime)=5";//周四
        }
        else if (qsType == 5)
        {
            sql = " LotteryType =" + lotteryType + " and datepart(weekday,openTime)=1";//周日
        }
        else if (qsType == 0)
        {
            sql = "LotteryType =" + lotteryType;
        }
        List<Model.LotteryAnnouncement> modellist = GetPageListSQl(0, count, sql, out totalCount);

        #region

        for (int i = modellist.Count - 1; i >= 0; i--)
        {
            string[] redBall = modellist[i].LotteryNo.Split('+')[0].Split(',');
            int max = 0;
            int min = 33;
            for (int m = 0; m < redBall.Length; m++)
            {
                int redBalls = int.Parse(redBall[m]);
                if (redBalls > max)
                {
                    max = redBalls;
                }
                if (redBalls < min)
                {
                    min = redBalls;
                }
            }
            //首球
            if (max % 2 == 0)
            {
                shouqiujiou += "1" + ","; //双
            }
            else
            {
                shouqiujiou += "0" + ","; //单
            }
            //int weishu=int.Parse(max.ToString().Substring(max.ToString().Length - 1, 1));
            if (min > 0 && min <= 6)
            {
                shouqiudx += "1" + ","; //小
            }
            else if (min >= 7 && min <= 33)
            {
                shouqiudx += "0" + ",";  //大 
            }
            if (max % 3 == 0)
            {
                shouqiusanlu += "0" + ","; //三路0
            }
            else if (max % 3 == 1)
            {
                shouqiusanlu += "1" + ","; //三路1
            }
            else if (max % 3 == 2)
            {
                shouqiusanlu += "2" + ","; //三路2
            }
            //尾球
            if (min % 2 == 0)
            {
                weiqiujiou += "1" + ","; //双
            }
            else
            {
                weiqiujiou += "0" + ","; //单
            }
            //int weiqiuweishu = int.Parse(min.ToString().Substring(min.ToString().Length - 1, 1));
            if (max <= 27)
            {
                weiqiudx += "1" + ","; //小
            }
            else if (max >= 28)
            {
                weiqiudx += "0" + ",";  //大 
            }
            if (min % 3 == 0)
            {
                weiqiusanlu += "0" + ","; //三路0
            }
            else if (min % 3 == 1)
            {
                weiqiusanlu += "1" + ","; //三路1
            }
            else if (min % 3 == 2)
            {
                weiqiusanlu += "2" + ","; //三路2
            }

            //首球尾球位数和值
            int weishu = int.Parse(max.ToString().Substring(max.ToString().Length - 1, 1));
            int weiqiuweishu = int.Parse(min.ToString().Substring(min.ToString().Length - 1, 1));
            int shouweihezhi = weiqiuweishu + weishu;
            if (shouweihezhi % 2 == 0)
            {
                shouweihezhijiou += "1" + ","; //双
            }
            else
            {
                shouweihezhijiou += "0" + ","; //单
            }
            if (shouweihezhi <= 9)
            {
                shouweihezhidx += "1" + ","; //小
            }
            else if (shouweihezhi >= 10)
            {
                shouweihezhidx += "0" + ",";  //大 
            }
            if (shouweihezhi % 3 == 0)
            {
                shouweihezhisanlu += "0" + ","; //三路0
            }
            else if (shouweihezhi % 3 == 1)
            {
                shouweihezhisanlu += "1" + ","; //三路1
            }
            else if (shouweihezhi % 3 == 2)
            {
                shouweihezhisanlu += "2" + ","; //三路2
            }
        }
        #endregion
        shouqiujiou = shouqiujiou.TrimEnd(',');
        shouqiudx = shouqiudx.TrimEnd(',');
        shouqiusanlu = shouqiusanlu.TrimEnd(',');
        weiqiujiou = weiqiujiou.TrimEnd(',');
        weiqiudx = weiqiudx.TrimEnd(',');
        weiqiusanlu = weiqiusanlu.TrimEnd(',');
        shouweihezhijiou = shouweihezhijiou.TrimEnd(',');
        shouweihezhidx = shouweihezhidx.TrimEnd(',');
        shouweihezhisanlu = shouweihezhisanlu.TrimEnd(',');
        Response.Write(shouqiujiou + "*" + shouqiudx + "*" + shouqiusanlu + "*" + weiqiujiou + "*" + weiqiudx + "*" + weiqiusanlu + "*" + shouweihezhijiou + "*" + shouweihezhidx + "*" + shouweihezhisanlu);
        Response.End();
    }
}